import datetime

import pymysql


def insert(sql, param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    con.commit()
    cur.close()
    con.close()


def select(sql, param, mode="all", size=0):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    if mode == "all":
        return cur.fetchall()
    if mode == "one":
        return cur.fetchone()
    if mode == "many":
        return cur.fetchmany(size=size)
    cur.close()
    con.close()


def delete(sql, param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    con.commit()
    cur.close()
    con.close()


def update(sql, param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    con.commit()
    cur.close()
    con.close()


def execute(sql):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql)
    con.commit()
    cur.close()
    con.close()


# sql = "select 时间 from guanjia"
# # p = "20220421"
# for i in select(sql, None, mode="all"):
#     if datetime.date(2022,4,23) in i:
#         print("对")
#         break
#     else:
#         continue

# print(datetime.date(0, 0, 0))